﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.Common;
using Api.IServices;
using Api.Model;
using Api.Model.Dto.TagDto;
using Api.Model.Model;
using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TagController : ApiBaseController
    {
        private readonly ITagServices _tagServices;
        private readonly IMapper _mapper;

        public TagController(ITagServices tagServices,IMapper mapper)
        {
            _tagServices = tagServices;
            _mapper = mapper;
        }
        [HttpPost]
        public async Task<GetTagOutput> CreateTagAsync(CreateTagInput input)
        {
            return await _tagServices.CreateTagAsync(input); 
        }
        [HttpGet]
        public async Task<List<GetTagOutput>> GetTagListAsync([FromQuery]GetTagInput input)
        {
           var res =  await _tagServices.GetTagListAsync(input);
            var tags = _mapper.Map<List<GetTagOutput>>(res);
            return tags;
        }
        [HttpGet]
        public async Task<Dictionary<int,GetTagOutput>> GetTagDicAsync([FromQuery]GetTagInput input)
        {
            var res = await  _tagServices.GetTagListAsync(input);
            var tags = _mapper.Map<List<GetTagOutput>>(res);
            return tags.ToDictionary(x => x.Id);
        }
        [HttpPut]
        public async Task UpdateTagAsync(UpdateTagInput input)
        {
            await _tagServices.UpdateTagAsync(input);
        }
        [HttpDelete]
        public async Task DeleteTagAsync(int? id)
        {
            await _tagServices.DeleteTagAsync(id.GetValueOrDefault());
        }
    }
}